//
//  zhuce.m
//  HappyStore
//
//  Created by 点点充 on 16/1/12.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "zhuce.h"
#import "AreasConcern.h"

@interface zhuce ()<UIActionSheetDelegate>
{
    NSString *strType;
    NSArray *hangYeArr;//所属行业
}
@end

@implementation zhuce

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.translucent = YES;
    [self.view setFrame:CGRectMake(0, 0, screenW, screenH)];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    strType = @"1";
    
    hangYeArr = @[@"生物医药", @"旅游休闲", @"制造业", @"批发零售", @"房地产业", @"交通运输", @"冶金矿产",
                  @"建筑建材", @"信息软件", @"金融", @"教育", @"现代服务业", @"生态环保", @"市政基建", @"文体娱乐",
                  @"社会保障", @"水电燃气", @"农林牧渔", @"其他"];
    
    //监听关注领域
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(areasConcernStr:) name:@"AreasConcernStr" object:nil];
    [self.chickXieYi addTarget:self action:@selector(chickXieYiWebView) forControlEvents:UIControlEventTouchUpInside];
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}
//用户协议
- (void)chickXieYiWebView{
    NSURL *url = [NSURL URLWithString:@"http://www.lensum.com/user_agreement.html"];
    UIViewController *XieYiVC = [[UIViewController alloc] init];
    // 设置返回按钮
    UIBarButtonItem *leftItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftBarButtonItemClick) image:@"Back" highImage:@"Back"];
    XieYiVC.navigationItem.leftBarButtonItem = leftItem;

    UIWebView *XieYiWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, screenW, screenH)];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [XieYiWebView loadRequest:request];
    XieYiVC.view = XieYiWebView;
    [self.navigationController pushViewController:XieYiVC animated:YES];
   
    

}
- (void)leftBarButtonItemClick{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 3个按钮点击事件
//ssdd
- (IBAction)btnClickThree:(UIButton *)sender
{
    [sender setTitleColor:[UIColor colorWithRed:32/255.0 green:165/255.0 blue:240/255.0 alpha:1.0f] forState:UIControlStateNormal];
    _imgView_HengTiao.translatesAutoresizingMaskIntoConstraints = YES;
    CGRect rect1 = _imgView_HengTiao.frame;
    switch (sender.tag) {
        case 10://个人用户
        {
            strType = @"1";
            [_btnZhengfu setTitleColor:[UIColor colorWithRed:85/255.0 green:85/255.0 blue:85/255.0 alpha:1.0f] forState:UIControlStateNormal];
            [_btnQiYe setTitleColor:[UIColor colorWithRed:85/255.0 green:85/255.0 blue:85/255.0 alpha:1.0f] forState:UIControlStateNormal];
            //x:36 w:87
            rect1.origin.x = 36;
            
            self.lbHangYe.hidden = YES;
            self.viewHangYe.hidden = YES;
            self.lbName.hidden = NO;
            self.viewName.hidden = NO;
            self.lbLingYu.hidden = NO;
            self.viewLingYu.hidden = NO;
            
            self.tfHangYe.text = @"";
        }
            break;
        case 11://企业用户
        {
            strType = @"2";
            [_btnZhengfu setTitleColor:[UIColor colorWithRed:85/255.0 green:85/255.0 blue:85/255.0 alpha:1.0f] forState:UIControlStateNormal];
            [_btnUser setTitleColor:[UIColor colorWithRed:85/255.0 green:85/255.0 blue:85/255.0 alpha:1.0f] forState:UIControlStateNormal];
            //x:123
            rect1.origin.x = 123;
            
            self.lbHangYe.hidden = NO;
            self.viewHangYe.hidden = NO;
            self.lbName.hidden = NO;
            self.viewName.hidden = NO;
            self.lbLingYu.hidden = NO;
            self.viewLingYu.hidden = NO;
        }
            break;
        case 12://政府用户
        {
            strType = @"3";
            [_btnUser setTitleColor:[UIColor colorWithRed:85/255.0 green:85/255.0 blue:85/255.0 alpha:1.0f] forState:UIControlStateNormal];
            [_btnQiYe setTitleColor:[UIColor colorWithRed:85/255.0 green:85/255.0 blue:85/255.0 alpha:1.0f] forState:UIControlStateNormal];
            //x:210
            rect1.origin.x = 210;
            
            self.lbHangYe.hidden = YES;
            self.viewHangYe.hidden = YES;
            self.lbName.hidden = YES;
            self.viewName.hidden = YES;
            self.lbLingYu.hidden = YES;
            self.viewLingYu.hidden = YES;
            
            self.tfHangYe.text = @"";
            self.tfLingYu.text = @"";
            self.tfName.text = @"";
        }
            break;
    }
    
    _imgView_HengTiao.frame = rect1;
}
//关注领域
- (IBAction)jumpLingYu:(UIButton *)sender {
    
    AreasConcern *areasConcernVC = [[AreasConcern alloc] init];
    areasConcernVC.titleString = @"关注领域";
    [self.navigationController pushViewController:areasConcernVC animated:YES];
}


- (void)areasConcernStr:(NSNotification *)noti{
    NSDictionary * mudic = [NSDictionary dictionaryWithDictionary:noti.userInfo];
    self.tfLingYu.text = mudic[@"string"];
}

//所属行业
- (IBAction)jumpHangYe:(UIButton *)sender {
    
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"所属行业"
                                                             delegate:self
                                                    cancelButtonTitle:@"取消"
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:@"生物医药", @"旅游休闲", @"制造业", @"批发零售", @"房地产业", @"交通运输", @"冶金矿产",
                                  @"建筑建材", @"信息软件", @"金融", @"教育", @"现代服务业", @"生态环保", @"市政基建", @"文体娱乐",
                                  @"社会保障", @"水电燃气", @"农林牧渔", @"其他", nil];
    
    actionSheet.tag = 100;
    [actionSheet showInView:self.view];
    
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    switch (actionSheet.tag) {
        case 100:
            self.tfHangYe.text = hangYeArr[buttonIndex];
            break;
            
        default:
            break;
    }

}

//发送验证码
- (IBAction)btnClickPostYZM:(UIButton *)sender
{
    BOOL isSuccess = YES;
    isSuccess = [_tfUserPhoneNum.text isValidPhoneNum];
    if (!isSuccess) {

        [self showSingleIconBubble:@"手机号码有误"];

    }else {
        //zc-yzm1-normal
        
        //1	获取验证码	http://cxs:8080/lensum/user_getCode_app_user.im	post	toCode:电话号码	{"result":"1","msg":"验证码发送手机成功!30分钟内有效!","data":"315925"}	{"result":"2","msg":"获取验证码失败，请仔细查看输入的接收端是否有误!","data":""}
        
        [self showRoundProgressWithTitle:@"请稍后..."];
        NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
        [muDicParameters setObject:_tfUserPhoneNum.text forKey:@"toCode"];//电话号码
        
        
        NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"user_getCode_app_user.im"];
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
//            NSLog(@"%@",dicInfo);

            if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {

                [self showRightWithTitle:[dicInfo objectForKey:@"msg"] autoCloseTime:2];
                [self startTime];
            }else {

                [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
            }

            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

            [self showSingleIconBubble:error.localizedDescription];

        }];
 
    }
    
    
    
    
}

//用户确认协议
- (IBAction)btnClickEnterProtel:(UIButton *)sender
{
    if (sender.selected) {
        sender.selected = NO;
    }else {
        sender.selected = YES;
    }
}

//开始注册
- (IBAction)btnClickZhuCe:(UIButton *)sender
{
    
    BOOL isSuccess = YES;
    isSuccess = [_tfUserPhoneNum.text isValidPhoneNum];
    if (!isSuccess) {

       [self showSingleIconBubble:@"手机号码有误"];

    }
    
    
    if (isSuccess== YES) {
//        if (_tfUserName.text.length==0 || _tfUserName.text.length<6) {
//            isSuccess = NO;
//            [SVProgressHUD showErrorWithStatus:@"输入的用户名长度不能少于6位!"];
//            [SVProgressHUD dismissafterDelay:kHideHudDelay];
//        }else if (_tfUserName.text.length >16)
//        {
//            isSuccess = NO;
//            [SVProgressHUD showErrorWithStatus:@"输入的用户名长度不能多于16位!"];
//            [SVProgressHUD dismissafterDelay:kHideHudDelay];
//        }else{
//            NSString * regex = @"^[A-Za-z0-9]{9,15}$";
//            NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
//            isSuccess = [pred evaluateWithObject:_tfUserName.text];
//            if (!isSuccess) {
//                [SVProgressHUD showErrorWithStatus:@"输入的用户名不能包含汉字!"];
//                [SVProgressHUD dismissafterDelay:kHideHudDelay];
//            }
//        }
    }
    
    if (isSuccess == YES) {
        if (_tfYZM.text.length != 6) {
            isSuccess = NO;

            [self showSingleIconBubble:@"验证码长度不等于6位"];

        }
    }
    
    if (isSuccess == YES) {
        if (_tfPassWord.text.length < 6) {
            isSuccess = NO;
 
            [self showSingleIconBubble:@"密码小于6位"];

        }
    }
    
    
    if (isSuccess==YES) {
        if (!_btnXieYi.selected) {
            isSuccess = NO;
            [self showSingleIconBubble:@"未勾选协议"];

        }
    }
    
    if (isSuccess==YES) {
        if ([strType isEqualToString:@"1"]) {
            if (self.tfUserName.text.length < 2 && self.tfLingYu.text.length < 2) {
                    isSuccess = NO;

                [self showSingleIconBubble:@"资料未完善"];
            }
            
        }else if ([strType isEqualToString:@"2"]){
            if (self.tfUserName.text.length < 2 && self.tfLingYu.text.length < 2 && self.tfHangYe.text.length < 2) {
                isSuccess = NO;
                 [self showSingleIconBubble:@"资料未完善"];
            }
        
        }
    }
    
    if (isSuccess) {
        //code=验证码&account=登录用户名&phone=手机号码&email=Email&password=密码&userType=用户类型1-个人 2-企业 3-政府&licenseNo=营业执照号&companyorganizationCode=企业组织机构代码&goveorganizationCode=政府组织机构代码
        [self showRoundProgressWithTitle:@"请稍后..."];
        NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
        [muDicParameters setObject:_tfYZM.text forKey:@"code"];//验证码
//        [muDicParameters setObject:_tfUserName.text forKey:@"account"];//登录用户名
//         [muDicParameters setObject:_tfUserPhoneNum.text forKey:@"account"];//登录用户名
        [muDicParameters setObject:_tfUserPhoneNum.text forKey:@"phone"];//手机号码
        [muDicParameters setObject:_tfPassWord.text forKey:@"password"];//密码
        [muDicParameters setObject:strType forKey:@"userType"];//用户类型1-个人 2-企业 3-政府
        
        NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"registered_app_user.im"];
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
//            NSLog(@"%@",dicInfo);
            
            if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
                //"data":[{"phone":"13896438419","email":"","token":"SX8QbfVIl6RAXqwjgUn8","userid":9,"account":"cxs123","usertype":1,"password":"e10adc3949ba59abbe56e057f20f883e"}]
                NSDictionary *dicUserInfo = [dicInfo objectForKey:@"data"][0];
                
                allConstMemberid = dicUserInfo[@"userid"];
                allConstMemberToken = dicUserInfo[@"token"];
                
                [USER_DEFAULTS setObject:dicUserInfo[@"token"] forKey:@"token"];
                [USER_DEFAULTS setObject:dicUserInfo[@"phone"] forKey:@"phone"];
                [USER_DEFAULTS setObject:dicUserInfo[@"userid"] forKey:@"userid"];
                [USER_DEFAULTS setObject:dicUserInfo[@"account"] forKey:@"account"];
                [USER_DEFAULTS setObject:dicUserInfo[@"usertype"] forKey:@"usertype"];
                [USER_DEFAULTS setObject:dicUserInfo[@"password"] forKey:@"password"];
                [USER_DEFAULTS synchronize];
                
                NSString *strURl;
                
                if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 1) {//个人
                    
                    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
                    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
                    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
                    [muDicParameters setObject:self.tfName.text forKey:@"userName"];//资源类型
                    
                    strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"updateUser_People_app_myHome.im.lensum"];
                    
                    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                    [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
                        
                    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                        
                        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
                        //        NSLog(@"%@",dicInfo);
                        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
                            
                            NSLog(@"注册个人名称成功");
                            
                            NSMutableDictionary *muDicParameter = [NSMutableDictionary dictionary];
                            [muDicParameter setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
                            [muDicParameter setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
                            [muDicParameter setObject:self.tfLingYu.text forKey:@"goodatfield"];//资源类型
                            
                            AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                            [manager POST:strURl parameters:muDicParameter progress:^(NSProgress * _Nonnull uploadProgress) {
                                
                            } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                                
                                NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
                                //        NSLog(@"%@",dicInfo);
                                if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
                                    
                                    NSLog(@"注册个人关注领域成功");
                                    
                                }else {
                                    

                                   [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
                                }
                                
                            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

                                 [self showErrorWithTitle:@"1" autoCloseTime:2];
                                
                            }];
                            
                            
                        }else {

                           [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
                        }
                        
                    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

                        [self showErrorWithTitle:@"1" autoCloseTime:2];
                        
                    }];
                    
                }else if ([[USER_DEFAULTS objectForKey:@"usertype"] integerValue] == 2) {//企业
                    
                    strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"updateUser_Company_app_myHome.im.lensum"];
                    
                    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
                    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
                    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
                    [muDicParameters setObject:self.tfName.text forKey:@"userName"];//资源类型
                    
                    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                    [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
                        
                    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                        
                        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
                        //        NSLog(@"%@",dicInfo);
                        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
                            
                            NSLog(@"注册企业名称成功");
                            
                            NSMutableDictionary *muDicParameter = [NSMutableDictionary dictionary];
                            [muDicParameter setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
                            [muDicParameter setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
                            [muDicParameter setObject:self.tfLingYu.text forKey:@"companyField"];//资源类型
                            
                            AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                            [manager POST:strURl parameters:muDicParameter progress:^(NSProgress * _Nonnull uploadProgress) {
                                
                            } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                                
                                NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
                                //        NSLog(@"%@",dicInfo);
                                if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
                                    
                                    NSLog(@"注册企业关注领域成功");
                                    
                                    NSMutableDictionary *muDic = [NSMutableDictionary dictionary];
                                    [muDic setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
                                    [muDic setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
                                    [muDic setObject:self.tfHangYe.text forKey:@"companyIndustry"];//资源类型
                                    
                                    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
                                    [manager POST:strURl parameters:muDic progress:^(NSProgress * _Nonnull uploadProgress) {
                                        
                                    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                                        
                                        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
                                        //        NSLog(@"%@",dicInfo);
                                        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
                                            
                                            NSLog(@"注册企业所属行业成功");
                                            
                                        }else {

                                            [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
                                        }
                                        
                                    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

                                        [self showErrorWithTitle:@"1" autoCloseTime:2];
                                        
                                    }];
                                    
                                }else {

                                   [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
                                }
                                
                            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

                                [self showErrorWithTitle:@"1" autoCloseTime:2];
                                
                            }];
                            
                            
                        }else {

                            [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
                        }
                        
                    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

                        [self showErrorWithTitle:@"1" autoCloseTime:2];
                        
                    }];
                }

                //去首页
                UIStoryboard *LoginAndRegister = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
                UITabBarController *tabBarC = [LoginAndRegister instantiateViewControllerWithIdentifier:@"homeTabBar"];
                [self presentViewController:tabBarC animated:YES completion:nil];
                [self hideBubble];
                
            }else {
                [self hideBubble];

                UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"提示" message:[dicInfo objectForKey:@"msg"] delegate:self cancelButtonTitle:@"取消" otherButtonTitles: nil];
                [alert show];
            }
            

        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

            [self showSingleIconBubble:error.localizedDescription];

        }];
    }
    
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if (textField == _tfUserName) {
        _imgV_UserName.image = [UIImage imageNamed:@"zc-bk-selected"];
    }
    
    if (textField == _tfUserPhoneNum) {
        _imgV_UserPhoneNum.image = [UIImage imageNamed:@"zc-bk-selected"];
    }
    if (textField == _tfYZM) {
        _imgV_YZM.image = [UIImage imageNamed:@"zc-bk-selected"];
    }
    if (textField == _tfPassWord) {
        _imV_Mima.image = [UIImage imageNamed:@"zc-bk-selected"];
    }
    
    
    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField == _tfUserName) {
        _imgV_UserName.image = [UIImage imageNamed:@"zc-bk-normal"];
    }
    
    if (textField == _tfUserPhoneNum) {
        _imgV_UserPhoneNum.image = [UIImage imageNamed:@"zc-bk-normal"];
    }
    if (textField == _tfYZM) {
        _imgV_YZM.image = [UIImage imageNamed:@"zc-bk-normal"];
    }
    if (textField == _tfPassWord) {
        _imV_Mima.image = [UIImage imageNamed:@"zc-bk-normal"];
    }
}

-(void)startTime{
    __block int timeout = 30; //倒计时时间
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
    dispatch_source_set_event_handler(_timer, ^{
        if(timeout<=0){ //倒计时结束，关闭
            dispatch_source_cancel(_timer);
            dispatch_async(dispatch_get_main_queue(), ^{
                //设置界面的按钮显示 根据自己需求设置
                [_btnYZM setBackgroundImage:[UIImage imageNamed:@"zc-yzm1-normal"] forState:UIControlStateNormal];
                [_btnYZM setTitle:@"" forState:UIControlStateNormal];
                _btnYZM.userInteractionEnabled = YES;
            });
        }else{
            int seconds = timeout % 60;
            NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
            [_btnYZM setBackgroundImage:[UIImage imageNamed:@"zc-yzm1-selected"] forState:UIControlStateNormal];
            dispatch_async(dispatch_get_main_queue(), ^{
                //设置界面的按钮显示 根据自己需求设置
                //NSLog(@"____%@",strTime);
                [UIView beginAnimations:nil context:nil];
                [UIView setAnimationDuration:1];
                
                [_btnYZM setTitle:[NSString stringWithFormat:@"%@s",strTime] forState:UIControlStateNormal];
                [UIView commitAnimations];
                _btnYZM.userInteractionEnabled = NO;
            });
            timeout--;
        }
    });
    dispatch_resume(_timer);
}


@end
